<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>
<body>
    <div id="app">
           <!--   父向子传值     监听change事件（子向父传值） -->
        <counter :count="1" @change="handleincrease"></counter>
        <counter :count="2" @change="handleincrease"></counter>
        <div>{{total}}</div>
    </div>
    <script>
        var counter={
            props:['count'],
            data:function(){
                return{
                    number:this.count/* 定义属性接收父组件传的数据 */
                }
            },
            template:'<div @click="handleclick">{{number}}</div>',
            methods:{
                handleclick:function(){
                    this.number+=2;
                    this.$emit('change',2);//向外触发change事件
                }
            }
        }
        var vm=new Vue({
            el:'#app',
            data:{
                total:3
            },
            methods:{
                handleincrease:function(a){
                    this.total+=a;
                }
            },
            components:{
                counter:counter
            }
        })
    </script>
</body>
</html>